home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 2 / ETO Development Tools 2.iso / Tools - Objects / MacApp / MacApp CD Release / MacApp 2.0.1 (Many Libraries) / Examples / DrawShapes / UDrawShapes.p < prev    next >
Encoding:
Text File  |  1990-10-25  |  24.1 KB  |  719 lines  |  [TEXT/MPS ]

  1. {[a-,body+,h-,o=100,r+,rec+,t=4,u+,#+,j=20/57/1$,n+]}
  2. { UDrawShapes.p}
  3. { Copyright © 1986-1990 by Apple Computer, Inc. All rights reserved.}
  4.  
  5. { **** Still to do on this sample: ****
  6.  
  7. Scroll selection into view when doing, undoing, or redoing commands
  8. (as in OneBox)
  9. }
  10. {[f-]}
  11. {
  12. This is a sample application illustrating numerous features of MacApp and the
  13. Printing building block.
  14.  
  15. The application's windows show a palette at left, and a drawing area to the
  16. right; this is similar to MacDraw and MacPaint.
  17.  
  18. In the windows, the user can draw quadrilaterals and ovals (choosing which
  19. from the palette) and can move already-drawn shapes around.
  20.  
  21. Command-D is used to toggle the availability of a special 'More Debug' menu
  22. in the menu bar, both to illustrate how to have commands on command-keys that
  23. aren't themselves in the menu and how to insert and delete menus dynamically.
  24. Three special debugging commands are only available when this special menu
  25. is inserted.
  26.  
  27. Full Clipboard support is also illustrated, including most features that any
  28. application would be likely to need.  Shapes can be cut or pasted between
  29. documents, and picture-versions of shapes on the Clipboard can be pasted into
  30. other applications such as MacPaint.
  31.  
  32. Printing and Filing are also supported.  Window state is preserved in saved
  33. files.    Filing uses both data and resource forks, to illustrate both
  34. techniques.
  35.  
  36. All commands are undoable.    Commands illustrated include commands to Draw,
  37. commands to move objects around within the view, and commands to change
  38. properties of objects.
  39.  
  40. Hold the OPTION key down while drawing to constrain the drawing to be a
  41. square/circle rather than a general rectangle/oval while sketching.  This
  42. constrains the object being drawn to be a square/circle whose side/diameter
  43. is a horizontal or vertical offset of the mouse from the anchor point,
  44. whichever is SMALLER.  This may feel a bit strange in practice, but it does
  45. illustrate a feature.
  46. }
  47. {[f+]}
  48.  
  49. UNIT UDrawShapes;
  50.  
  51.     INTERFACE
  52.  
  53.         USES
  54.             { • MacApp }
  55.             UMacApp,
  56.  
  57.             { • Building Blocks }
  58.             UPrinting, UBetterFeedbackCmd, UMenu,
  59.  
  60.             { • Implementation Use }
  61.             Picker, ToolUtils, Resources, Fonts;
  62.  
  63.         CONST
  64.  
  65.             { graphic menu }
  66.  
  67.             kShadesMenu         = 5;                    { the resource ID of our menu }
  68.  
  69.             { Shades custom pulldown menu, menu drawing placement parameters }
  70.             kShadesAcross        = 3;                    { how many shades across }
  71.             kShadesDown         = 2;                    { how many shades down }
  72.             kTotalShades        = kShadesAcross * kShadesDown;
  73.  
  74.  
  75.             kShadeTop            = 3;                    { how far down to draw boxes containing
  76.                                                          shades}
  77.             kShadeLeft            = 3;                    { how far from left to begin drawing }
  78.             kWShadeCell         = 24;                    { Width of Cell }
  79.             kHShadeCell         = 24;                    { Height of Cell }
  80.             kWCellSpace         = 1;                    { width spacing between cells }
  81.             kHCellSpace         = 1;                    { height spacing between cells }
  82.             kWShadeChoice        = kShadeLeft + ((kWShadeCell + kWCellSpace) * kShadesAcross);
  83.             kHShadeChoice        = (kHShadeCell + kHCellSpace) * kShadesDown;
  84.  
  85.             { command numbers }
  86.  
  87.             cShadeBase            = 1000;
  88.             cWhite                = 1000;                 {The five shades in the 'Shades' menu}
  89.             cLtGray             = 1001;
  90.             cGray                = 1002;
  91.             cDkGray             = 1003;
  92.             cBlack                = 1004;
  93.             cShadeMax            = 1004;
  94.             kNoOfShades         = cShadeMax - cShadeBase + 1;
  95.  
  96.             cPickColor            = 1005;                 {Use Color Picker for shape's color}
  97.  
  98.             cNewShape            = 1010;                 {Drawing a new shape}
  99.             cMoveShape            = 1011;                 {Moving one or more shapes}
  100.  
  101.             cCmdDTyped            = 1200;                 {Command representing the fact that the user
  102.                                                          typed "Command-D"; in this app this is
  103.                                                          used as a signal to put up the "More
  104.                                                          Debug" menu, or if it is already up, to
  105.                                                          take it down -- thus demonstrating both
  106.                                                          how to handle commands not in the menu bar
  107.                                                          and how to put entire menus up and take
  108.                                                          them down dynamically}
  109.  
  110.         { The following three commands are only available in the 'More Debug' menu,
  111.          which is only accessible if you type Cmd-D to insert that menu into
  112.          the menu bar }
  113.  
  114.             cPasteReplacesSelection = 118;                {Debugging: whether pasting into a shapeView
  115.                                                          should supplant any existing selection or
  116.                                                          not; if not, the pastee instead is
  117.                                                          centered in the window}
  118.             cRecalcExtent        = 119;                    {Debugging: performs immediate recomputation
  119.                                                          of view extent; if gConstrainDrags is
  120.                                                          FALSE, it is possible for a shape to be
  121.                                                          beyond the view border; the view's extent
  122.                                                          can be refigured on demand by using this
  123.                                                          command}
  124.             cConstrainDrags     = 120;                    {Debugging: whether shape-dragging should be
  125.                                                          constrained so that the entire selection
  126.                                                          fits within the view or not}
  127.             cBetterFeedback     = 121;                    {Debugging: whether to use the code which
  128.                                                          provides better TrackFeedback}
  129.  
  130.             { Resource types and Resource IDs }
  131.  
  132.             kDocRsrcKind        = 'DSTA';                {Resource type for document state}
  133.             kDocStateID         = 1;                    {Resource id for document state}
  134.  
  135.             kShapeWindowRSRCID    = 1005;                 {Resource id for the windows used by
  136.                                                          documents in the application}
  137.             kShapeViewRSRCID    = 1006;                    {Resource id for the shape view template,
  138.                                                         used when printing & using template views }
  139.  
  140.             kDocType            = 'SF05';                {File-type for document files created by
  141.                                                          this application}
  142.             kSignature            = 'SS05';                {Application signature; Creator type for
  143.                                                          documents}
  144.  
  145.             kShapeClipType        = 'SHAP';                {Clipboard type for my shapes}
  146.  
  147.             mColor                = 6;                    {The Color menu resource id}
  148.  
  149.             mMoreDebug            = 7;                    {Menu number for the 'More Debug' menu}
  150.  
  151.             { Miscellaneous }
  152.  
  153.             IDBox                = 1;                    {ID of TBox items}
  154.             IDCircle            = 2;                    {ID of TCircle items}
  155.             IDhBox                = 3;                    {IDF of THeavyBox}
  156.  
  157.             kShapesInPalette    = 3;                    {Number of shapes in the palette, in
  158.                                                          addition to the arrow}
  159.  
  160.         TYPE
  161.  
  162.     { Document state: stored in the Resource Fork of the document file; holds the
  163.       following general properties of the document, necessary for rereading
  164.       a saved document and restoring the appearance of the window (location,
  165.       size, and scrolling) to its state when last saved }
  166.             DocState            = RECORD
  167.                 theNumberOfShapes:    INTEGER;
  168.                 theWindowRect:        Rect;
  169.                 theScrollPosition:    VPoint;
  170.                 END;
  171.             HDocState            = ^PDocState;            {Handle to DocState information}
  172.             PDocState            = ^DocState;            {Pointer to DocState information}
  173.  
  174.     { Information about a single shape; same format used both in the data file
  175.       and in the desk scrap }
  176.             ShapeData            = RECORD
  177.                 theId:                INTEGER;            {1 => rectangle; 2 => oval; etc.}
  178.                 theRect:            Rect;                {the shape's extent}
  179.                 theShade:            INTEGER;            {the shape's current shade}
  180.                 theColor:            RGBColor;            {the shape's current color}
  181.                 theSelected:        BOOLEAN;            {for saving window state; not relevant for
  182.                                                          clipboard}
  183.                 END;
  184.  
  185.             { Data types used for storing shapes in the Desk Scrap }
  186.             ShapesOnClipboard    = ^PShapesOnClipboard;
  187.             PShapesOnClipboard    = ^ShapeClipRecord;
  188.             ShapeClipRecord     = RECORD
  189.                 theNumberOfShapes:    INTEGER;
  190.                 theBoundingBox:     Rect;
  191.                 theShapes:            ARRAY [0..1536] OF ShapeData;
  192.                 END;
  193.  
  194.             TShapeApplication    = OBJECT (TApplication)
  195.  
  196.             { Initialization }
  197.                 PROCEDURE TShapeApplication.IShapeApplication;
  198.  
  199.                 { Document creation }
  200.                 FUNCTION TShapeApplication.DoMakeDocument(itsCmdNumber: CmdNumber): TDocument;
  201.                     OVERRIDE;
  202.  
  203.                 { Commands }
  204.                 {$IFC qDebug}
  205.                 FUNCTION TShapeApplication.DoCommandKey(ch: CHAR;
  206.                     VAR info: EventInfo): TCommand; OVERRIDE;
  207.                 FUNCTION TShapeApplication.DoMenuCommand(aCmdNumber: CmdNumber): TCommand; OVERRIDE;
  208.                 PROCEDURE TShapeApplication.DoSetupMenus; OVERRIDE;
  209.                 {$ENDC}
  210.  
  211.                 FUNCTION TShapeApplication.MakeViewForAlienClipboard: TView; OVERRIDE;
  212.                 { Handle data found left in the Clipboard by forces outside the application }
  213.  
  214.                 { Debugging }
  215.                 {$IFC qDebug}
  216.                 PROCEDURE TShapeApplication.IdentifySoftware; OVERRIDE;
  217.                 {$ENDC}
  218.  
  219.                 END;
  220.  
  221.             {$IFC qHasForward}
  222.             TShape                 = OBJECT;    FORWARD;
  223.             TShapeView             = OBJECT;    FORWARD;
  224.             TPalette            = OBJECT;    FORWARD;
  225.             TShapeReplaceCommand = OBJECT;    FORWARD;
  226.             {$EndC}
  227.  
  228.             TShapeDocument        = OBJECT (TDocument)
  229.  
  230.                 fShapeView:         TShapeView;
  231.                 fPaletteView:        TPalette;
  232.                 fShapeList:         TList;
  233.  
  234.                 fDocState:            DocState;
  235.                 fReopening:         BOOLEAN;
  236.  
  237.                 fReplaceCommand:    TShapeReplaceCommand; {Tells us what the current replace command
  238.                                                            is (Cut, Paste). NIL means there is no
  239.                                                            current replace command.}
  240.                 fFiltering:         BOOLEAN;            {Tells us whether shapes that are
  241.                                                          'wasSelected' are not to be drawn if
  242.                                                          gLastCmdDone is TRUE}
  243.  
  244.                                 { Initialize and Free }
  245.  
  246.                 PROCEDURE TShapeDocument.IShapeDocument(fileType: OSType);
  247.                 PROCEDURE TShapeDocument.Free; OVERRIDE;
  248.                 PROCEDURE TShapeDocument.FreeData; OVERRIDE;
  249.  
  250.                 { Adding/deleting shapes }
  251.  
  252.                 PROCEDURE TShapeDocument.AddShape(shape: TShape);
  253.                 PROCEDURE TShapeDocument.DeleteShape(shape: TShape);
  254.  
  255.                 { Enumeration of shapes }
  256.  
  257.                 PROCEDURE TShapeDocument.EachShapeDo(PROCEDURE
  258.                                                      DoThis(shape: TShape));
  259.                 { Iterate through the list of shapes }
  260.  
  261.                 PROCEDURE TShapeDocument.EachPotentialShapeDo(PROCEDURE
  262.                                                               DoThis(shape: TShape));
  263.                 { Iterate through all the shapes in the document plus any
  264.                   'pastee' shapes which may have been added by a not-yet-committed PASTE. }
  265.  
  266.                 PROCEDURE TShapeDocument.EachVirtualShapeDo(PROCEDURE
  267.                                                             DoThis(shape: TShape));
  268.                 { Iterate through only those shapes that appear to be present at the moment
  269.                   to the USER, given the UNDO/REDO status of the last command.
  270.                   Thus it iterates through some but possibly not all of the the shapes in the
  271.                   document, and possibly also through not-yet-in-the-document pastees. }
  272.  
  273.                 FUNCTION TShapeDocument.FirstSelectedShapeThat(FUNCTION
  274.                                                                TestSelectedShape(aShape: TShape):
  275.                                                                BOOLEAN): TShape;
  276.  
  277.                 PROCEDURE TShapeDocument.SurveyShapes(selecteesOnly: BOOLEAN;
  278.                                                       VAR numberOfShapes: INTEGER;
  279.                                                       VAR combinedExtent: Rect);
  280.  
  281.                 { Overrides of basic TDocument methods }
  282.  
  283.                 PROCEDURE TShapeDocument.DoMakeViews(forPrinting: BOOLEAN); OVERRIDE;
  284.                 PROCEDURE TShapeDocument.DoNeedDiskSpace(VAR dataForkBytes,
  285.                     rsrcForkBytes: LONGINT); OVERRIDE;
  286.  
  287.                 PROCEDURE TShapeDocument.DoRead(aRefNum: INTEGER; rsrcExists,
  288.                     forPrinting: BOOLEAN); OVERRIDE;
  289.                 PROCEDURE TShapeDocument.DoWrite(aRefNum: INTEGER; makingCopy: BOOLEAN); OVERRIDE;
  290.  
  291.                 { Inspecting }
  292.                 PROCEDURE TShapeDocument.Fields(PROCEDURE
  293.                                                 DoToField(fieldName: Str255; fieldAddr: Ptr;
  294.                                                           fieldType: INTEGER)); OVERRIDE;
  295.  
  296.                 END;
  297.  
  298.             TPalette            = OBJECT (TView)
  299.  
  300.                 fCurrShape:         INTEGER;            {currently selected shape, or 0 for the
  301.                                                          arrow}
  302.  
  303.                 PROCEDURE TPalette.IPalette(itsDocument: TDocument);
  304.  
  305.                 {$IFC qTemplateViews}
  306.                 PROCEDURE TPalette.IRes(itsDocument: TDocument;
  307.                                          itsSuperview: TView;
  308.                                          VAR itsParams: Ptr); OVERRIDE;
  309.                 {$ENDC}
  310.  
  311.                 PROCEDURE TPalette.DoHighlightSelection(fromHL, toHL: HLState); OVERRIDE;
  312.  
  313.                 FUNCTION TPalette.DoMouseCommand(VAR theMouse: Point; VAR info: EventInfo;
  314.                                                  VAR hysteresis: Point): TCommand; OVERRIDE;
  315.  
  316.                 FUNCTION TPalette.DoSetCursor(localPoint: Point;
  317.                     cursorRgn: RgnHandle): BOOLEAN; OVERRIDE;
  318.  
  319.                 PROCEDURE TPalette.Draw(area: Rect); OVERRIDE;
  320.  
  321.                 { Inspecting }
  322.  
  323.                 PROCEDURE TPalette.Fields(PROCEDURE
  324.                                           DoToField(fieldName: Str255; fieldAddr: Ptr;
  325.                                                     fieldType: INTEGER)); OVERRIDE;
  326.  
  327.                 END;
  328.  
  329.             TShapeView            = OBJECT (TView)
  330.  
  331.                 fDragging:            BOOLEAN;            {tells us whether the mouse is dragging}
  332.                 fPalette:            TPalette;            {corresponding palette}
  333.  
  334.                 fClickPt:            Point;                {on PASTE, this is where the top-left point
  335.                                                          of the clipboard boxes go}
  336.                 fShapeDocument:     TShapeDocument;     {The associated document which owns the
  337.                                                          shapes}
  338.                 fScroller:            TScroller;            {corresponding scroller}
  339.  
  340.                                 { Initialization }
  341.                 PROCEDURE TShapeView.IShapeView(itsDocument: TShapeDocument; itsPalette: TPalette;
  342.                                                 forClipboard: BOOLEAN);
  343.                 { Initialize the view, associating it with the stated document
  344.                   and palette objects. Make it a view to be seen in the
  345.                   Clipboard only if 'forClipboard' is TRUE }
  346.  
  347.                 {$IFC qTemplateViews}
  348.                 PROCEDURE TShapeView.IRes(itsDocument: TDocument;
  349.                                          itsSuperview: TView;
  350.                                          VAR itsParams: Ptr); OVERRIDE;
  351.                 {$ENDC}
  352.                 
  353.                 { Size determination }
  354.                 PROCEDURE TShapeView.CalcMinSize(VAR minSize: VPoint); OVERRIDE;
  355.  
  356.                 { Menu commands }
  357.                 FUNCTION TShapeView.DoMenuCommand(aCmdNumber: CmdNumber): TCommand; OVERRIDE;
  358.                 { Handle the reshading and recoloring commands }
  359.  
  360.                 PROCEDURE TShapeView.DoSetupMenus; OVERRIDE;
  361.                 { Arm the menu items handled by DoMenuCommand }
  362.  
  363.                 { Mouse commands }
  364.                 FUNCTION TShapeView.DoMouseCommand(VAR theMouse: Point; VAR info: EventInfo;
  365.                                                    VAR hysteresis: Point): TCommand; OVERRIDE;
  366.  
  367.                 { Screen display }
  368.                 PROCEDURE TShapeView.DoHighlightSelection(fromHL, toHL: HLState); OVERRIDE;
  369.                 FUNCTION TShapeView.DoSetCursor(localPoint: Point;
  370.                     cursorRgn: RgnHandle): BOOLEAN; OVERRIDE;
  371.                 PROCEDURE TShapeView.Draw(area: Rect); OVERRIDE;
  372.                 PROCEDURE TShapeView.InvalShape(aShape: TShape);
  373.  
  374.                 { State transition }
  375.  
  376.                 PROCEDURE TShapeView.Deselect;
  377.                 PROCEDURE TShapeView.RestoreSelection;
  378.                 PROCEDURE TShapeView.SaveSelection(andInval: BOOLEAN);
  379.  
  380.                 { Methods only relevant for a shapeView installed in the Clipboard }
  381.  
  382.                 FUNCTION TShapeView.ContainsClipType(aType: ResType): BOOLEAN; OVERRIDE;
  383.                 PROCEDURE TShapeView.WriteToDeskScrap; OVERRIDE;
  384.  
  385.                 { Inspecting }
  386.  
  387.                 PROCEDURE TShapeView.Fields(PROCEDURE
  388.                                             DoToField(fieldName: Str255; fieldAddr: Ptr;
  389.                                                       fieldType: INTEGER)); OVERRIDE;
  390.  
  391.                 END;
  392.  
  393.             TShape                = OBJECT (TObject)
  394.                 fID:                INTEGER;
  395.                 fExtentRect:        Rect;                {size of object}
  396.                 fShade:             INTEGER;            {shade of object}
  397.                 fOldShade:            INTEGER;            {with the reshade command the Undo/Redo need
  398.                                                          to know the old shade}
  399.  
  400.                 fColor:             RGBColor;            {color of object}
  401.                 fOldColor:            RGBColor;            {with the recolor command the Undo/Redo need
  402.                                                          to know the old color}
  403.  
  404.                 fIsSelected:        BOOLEAN;            {is this shape selected?}
  405.                 fWasSelected:        BOOLEAN;            {old selection status, set when the last
  406.                                                          command was performed}
  407.  
  408.                                 { Initialization }
  409.  
  410.                 PROCEDURE TShape.Initialize; OVERRIDE;
  411.                 { Put the object into a known state from which it may be safely FREEd.
  412.                  (and hopefully a usable state) }
  413.  
  414.                 PROCEDURE TShape.IShape(itsExtent: Rect; itsID: INTEGER);
  415.                 { Initialize a shape procedurally }
  416.  
  417.                 { Screen display }
  418.  
  419.                 PROCEDURE TShape.Draw;
  420.                 PROCEDURE TShape.DrawOutline;
  421.  
  422.                 PROCEDURE TShape.EachHandleDo(PROCEDURE
  423.                                               DoThis(handle: Rect; handVHS: VHSelect;
  424.                                                      handTopOrLeft: BOOLEAN));
  425.  
  426.                 PROCEDURE TShape.Highlight(fromHL, toHL: HLState);
  427.  
  428.                 { Filing }
  429.  
  430.                 FUNCTION TShape.ID: INTEGER;
  431.                 { Used so that a filed shape can identify what kind of shape object
  432.                 is to be launched to represent it in memory }
  433.  
  434.                 PROCEDURE TShape.ReadFrom(aRefNum: INTEGER);
  435.                 { Read the shape from input file }
  436.  
  437.                 PROCEDURE TShape.WriteTo(aRefNum: INTEGER);
  438.                 { Write data characterizing the shape onto the Save-file }
  439.  
  440.                 { Inspecting }
  441.  
  442.                 PROCEDURE TShape.Fields(PROCEDURE DoToField(fieldName: Str255; fieldAddr: Ptr;
  443.                                                             fieldType: INTEGER)); OVERRIDE;
  444.  
  445.                 END;
  446.  
  447.             TBox                = OBJECT (TShape)
  448.  
  449.             { Initialization }
  450.  
  451.                 PROCEDURE TBox.IBox(itsExtent: Rect; itsID: INTEGER);
  452.  
  453.                 { Other methods }
  454.  
  455.                 PROCEDURE TBox.Draw; OVERRIDE;
  456.                 PROCEDURE TBox.DrawOutline; OVERRIDE;
  457.                 END;
  458.  
  459.             THeavyBox            = OBJECT (TBox)         { like a box except uses up 4K bytes }
  460.                 fFiller:            ARRAY [0..2048] OF INTEGER;
  461.  
  462.                 PROCEDURE THeavyBox.IHeavyBox(itsExtent: Rect; itsID: INTEGER);
  463.  
  464.                 PROCEDURE THeavyBox.Draw; OVERRIDE;
  465.                 END;
  466.  
  467.             TCircle             = OBJECT (TShape)
  468.  
  469.                 PROCEDURE TCircle.ICircle(itsExtent: Rect; itsID: INTEGER);
  470.  
  471.                 PROCEDURE TCircle.Draw; OVERRIDE;
  472.                 PROCEDURE TCircle.DrawOutline; OVERRIDE;
  473.                 END;
  474.  
  475.             TShapeCommand        = OBJECT (TBetterFeedbackCmd)
  476.             { This is a common ancestor for all commands operating on one or more shapes}
  477.  
  478.                 fShapeView:         TShapeView;
  479.                 fShapeDocument:     TShapeDocument;
  480.  
  481.                 PROCEDURE TShapeCommand.IShapeCommand(itsCmdNumber: CmdNumber;
  482.                                                       itsShapeView: TShapeView;
  483.                                                       betterFeedbackDesired: BOOLEAN);
  484.  
  485.                 { Inspecting }
  486.  
  487.                 PROCEDURE TShapeCommand.Fields(PROCEDURE
  488.                                                DoToField(fieldName: Str255; fieldAddr: Ptr;
  489.                                                          fieldType: INTEGER)); OVERRIDE;
  490.  
  491.                 END;
  492.  
  493.             TShapeSelector        = OBJECT (TShapeCommand)
  494.             { This command demonstrates the use of a command object that
  495.               is not saved and that does not commit the last command.
  496.               The same effect could have been achieved by selecting the
  497.               shapes in the TrackMouse method.}
  498.  
  499.                 fBounds:            Rect;
  500.                 fShiftKey:            BOOLEAN;
  501.  
  502.                 PROCEDURE TShapeSelector.IShapeSelector(itsCmdNumber: CmdNumber;
  503.                                                         itsShapeView: TShapeView);
  504.  
  505.                 PROCEDURE TShapeSelector.DoIt; OVERRIDE;
  506.  
  507.                 PROCEDURE TShapeSelector.TrackFeedback(anchorPoint, nextPoint: VPoint; turnItOn,
  508.                                                        mouseDidMove: BOOLEAN); OVERRIDE;
  509.  
  510.                 FUNCTION TShapeSelector.TrackMouse(aTrackPhase: TrackPhase; VAR anchorPoint,
  511.                                                    previousPoint, nextPoint: VPoint;
  512.                                                    mouseDidMove: BOOLEAN): TCommand; OVERRIDE;
  513.  
  514.                 { Inspecting }
  515.  
  516.                 PROCEDURE TShapeSelector.Fields(PROCEDURE
  517.                                                 DoToField(fieldName: Str255; fieldAddr: Ptr;
  518.                                                           fieldType: INTEGER)); OVERRIDE;
  519.  
  520.                 END;
  521.  
  522.             TShapeDragger        = OBJECT (TShapeCommand)
  523.  
  524.                 fBounds:            Rect;                {Union of fExtentRect of all shapes being
  525.                                                          dragged, before the move}
  526.                 fDeltaH:            INTEGER;
  527.                 fDeltaV:            INTEGER;
  528.  
  529.                                 { Initialization }
  530.  
  531.                 PROCEDURE TShapeDragger.IShapeDragger(aShapeView: TShapeView);
  532.  
  533.                 { Command performing }
  534.  
  535.                 PROCEDURE TShapeDragger.DoIt; OVERRIDE;
  536.                 PROCEDURE TShapeDragger.UndoIt; OVERRIDE;
  537.                 PROCEDURE TShapeDragger.RedoIt; OVERRIDE;
  538.  
  539.                 { Utility routine }
  540.  
  541.                 PROCEDURE TShapeDragger.MoveBy(deltaH, deltaV: INTEGER);
  542.  
  543.                 { Mouse Tracking }
  544.  
  545.                 PROCEDURE TShapeDragger.TrackConstrain(anchorPoint, previousPoint: VPoint;
  546.                                                        VAR nextPoint: VPoint); OVERRIDE;
  547.                 { Only if gConstrainDrags is TRUE is a shapeDragger marked as
  548.                   constraining the mouse, so be sure to make gConstrainsDrags TRUE
  549.                   before mousing down on something you want to drag under constraint.
  550.                   You manipulate the gConstrainsDrags flag through a toggle in the
  551.                   'More Debug' menu, which you get displayed by hitting Command-D }
  552.  
  553.                 PROCEDURE TShapeDragger.TrackFeedback(anchorPoint, nextPoint: VPoint; turnItOn,
  554.                                                       mouseDidMove: BOOLEAN); OVERRIDE;
  555.                 FUNCTION TShapeDragger.TrackMouse(aTrackPhase: TrackPhase; VAR anchorPoint,
  556.                                                   previousPoint, nextPoint: VPoint;
  557.                                                   mouseDidMove: BOOLEAN): TCommand; OVERRIDE;
  558.  
  559.                 { Inspecting }
  560.  
  561.                 PROCEDURE TShapeDragger.Fields(PROCEDURE
  562.                                                DoToField(fieldName: Str255; fieldAddr: Ptr;
  563.                                                          fieldType: INTEGER)); OVERRIDE;
  564.  
  565.                 END;
  566.  
  567.             TReshadeCmd         = OBJECT (TShapeCommand)
  568.             { Note that the set of shapes affected by the reshade request is
  569.               defined by the fWasSelected fields of the shapes themselves }
  570.  
  571.                 fShade:             INTEGER;
  572.  
  573.                                 { Command execution }
  574.  
  575.                 PROCEDURE TReshadeCmd.IReshadeCmd(itsCmdNumber: INTEGER; itsShapeView: TShapeView);
  576.                 PROCEDURE TReshadeCmd.DoIt; OVERRIDE;
  577.                 PROCEDURE TReshadeCmd.RedoIt; OVERRIDE;
  578.                 PROCEDURE TReshadeCmd.UndoIt; OVERRIDE;
  579.  
  580.                 END;
  581.  
  582.             TRecolorCmd         = OBJECT (TShapeCommand)
  583.             { Note that the set of shapes affected by the reshade request is
  584.               defined by the fWasSelected fields of the shapes themselves }
  585.  
  586.                 fColor:             RGBColor;
  587.  
  588.                 PROCEDURE TRecolorCmd.IRecolorCmd(itsColor: RGBColor; itsShapeView: TShapeView);
  589.                 PROCEDURE TRecolorCmd.DoIt; OVERRIDE;
  590.                 PROCEDURE TRecolorCmd.RedoIt; OVERRIDE;
  591.                 PROCEDURE TRecolorCmd.UndoIt; OVERRIDE;
  592.  
  593.                 END;
  594.  
  595.             TShapeReplaceCommand = OBJECT (TShapeCommand)
  596.             { This is a common ancestor for all commands that can add or delete shapes }
  597.  
  598.                 PROCEDURE TShapeReplaceCommand.Commit; OVERRIDE;
  599.                 PROCEDURE TShapeReplaceCommand.EachNewShapeDo(PROCEDURE
  600.                                                               DoThis(shape: TShape));
  601.                 FUNCTION TShapeReplaceCommand.FirstShapeThat(FUNCTION
  602.                                                              TestShape(aShape: TShape): BOOLEAN):
  603.                                                              TShape;
  604.                 PROCEDURE TShapeReplaceCommand.RedoIt; OVERRIDE;
  605.                 PROCEDURE TShapeReplaceCommand.UndoIt; OVERRIDE;
  606.                 END;
  607.  
  608.             TShapeSketcher        = OBJECT (TShapeReplaceCommand)
  609.  
  610.                 fShape:             TShape;             {the shape sketched by the user}
  611.  
  612.                 PROCEDURE TShapeSketcher.IShapeSketcher(aShapeView: TShapeView; protoShape: TShape;
  613.                                                         constrain: BOOLEAN);
  614.                 PROCEDURE TShapeSketcher.Free; OVERRIDE;
  615.  
  616.                 PROCEDURE TShapeSketcher.EachNewShapeDo(PROCEDURE
  617.                                                         DoThis(shape: TShape)); OVERRIDE;
  618.                 FUNCTION TShapeSketcher.FirstShapeThat(FUNCTION
  619.                                                        TestShape(aShape: TShape): BOOLEAN): TShape;
  620.                     OVERRIDE;
  621.  
  622.                 { Command performing }
  623.                 PROCEDURE TShapeSketcher.DoIt; OVERRIDE;
  624.                 PROCEDURE TShapeSketcher.RedoIt; OVERRIDE;
  625.                 PROCEDURE TShapeSketcher.UndoIt; OVERRIDE;
  626.  
  627.                 PROCEDURE TShapeSketcher.Commit; OVERRIDE;
  628.  
  629.                 { Mouse tracking }
  630.                 PROCEDURE TShapeSketcher.TrackConstrain(anchorPoint, previousPoint: VPoint;
  631.                                                         VAR nextPoint: VPoint); OVERRIDE;
  632.                 PROCEDURE TShapeSketcher.TrackFeedback(anchorPoint, nextPoint: VPoint; turnItOn,
  633.                                                        mouseDidMove: BOOLEAN); OVERRIDE;
  634.                 FUNCTION TShapeSketcher.TrackMouse(aTrackPhase: TrackPhase; VAR anchorPoint,
  635.                                                    previousPoint, nextPoint: VPoint;
  636.                                                    mouseDidMove: BOOLEAN): TCommand; OVERRIDE;
  637.  
  638.                 { Inspecting }
  639.  
  640.                 PROCEDURE TShapeSketcher.Fields(PROCEDURE
  641.                                                 DoToField(fieldName: Str255; fieldAddr: Ptr;
  642.                                                           fieldType: INTEGER)); OVERRIDE;
  643.  
  644.                 END;
  645.  
  646.             TShapeCutCopyCommand = OBJECT (TShapeReplaceCommand)
  647.  
  648.                 PROCEDURE TShapeCutCopyCommand.IShapeCutCopyCommand(itsCmdNumber: CmdNumber;
  649.                                                                     itsShapeView: TShapeView);
  650.                 PROCEDURE TShapeCutCopyCommand.DoIt; OVERRIDE;
  651.                 PROCEDURE TShapeCutCopyCommand.RedoIt; OVERRIDE;
  652.  
  653.                 END;
  654.  
  655.             TShapeClearCommand    = OBJECT (TShapeReplaceCommand)
  656.  
  657.                 PROCEDURE TShapeClearCommand.IShapeClearCommand(itsShapeView: TShapeView);
  658.  
  659.                 PROCEDURE TShapeClearCommand.DoIt; OVERRIDE;
  660.                 PROCEDURE TShapeClearCommand.RedoIt; OVERRIDE;
  661.  
  662.                 END;
  663.  
  664.             TShapePasteCommand    = OBJECT (TShapeReplaceCommand)
  665.  
  666.                 fPasteList:         TList;
  667.  
  668.                 PROCEDURE TShapePasteCommand.IShapePasteCommand(itsShapeView: TShapeView);
  669.  
  670.                 PROCEDURE TShapePasteCommand.Free; OVERRIDE;
  671.  
  672.                 PROCEDURE TShapePasteCommand.EachNewShapeDo(PROCEDURE
  673.                                                             DoThis(shape: TShape)); OVERRIDE;
  674.                 FUNCTION TShapePasteCommand.FirstShapeThat(FUNCTION
  675.                                                            TestShape(aShape: TShape): BOOLEAN):
  676.                                                            TShape; OVERRIDE;
  677.  
  678.                 PROCEDURE TShapePasteCommand.Commit; OVERRIDE;
  679.                 PROCEDURE TShapePasteCommand.DoIt; OVERRIDE;
  680.                 PROCEDURE TShapePasteCommand.UndoIt; OVERRIDE;
  681.                 PROCEDURE TShapePasteCommand.RedoIt; OVERRIDE;
  682.  
  683.                 END;
  684.  
  685.             { This is a simple menu example, it has many rough edges and can be greatly
  686.               improved.  Most custom menus you will create are regular (ie boxes across and
  687.               down).
  688.             
  689.               My original concept was to provide for irregularly spaced and placed boxes
  690.               with custom labels as well as a way to handle white space (see the sixth item in
  691.               this menu). The IShade method could be changed to create each rectangle by
  692.               hand should your prgram need to. FindItem returns a negative command
  693.               associated with each rectangle, thus the addition of the instance variables
  694.               fChoiceArray and fShadeCommands.    The other approach (and most common) would
  695.               be to have a method that calculates the item number from the mouse down
  696.               position.
  697.             
  698.              }
  699.             TShadeMenu            = OBJECT (TMenu)
  700.  
  701.                 fShadeCommands:     ARRAY [1..kTotalShades] OF INTEGER;
  702.                                 { array of menu commands we can select }
  703.  
  704.                 fChoiceArray:        ARRAY [1..kTotalShades] OF Rect;
  705.                                 { the rectangle in the menu where we can choose }
  706.  
  707.                 PROCEDURE TShadeMenu.IShadeMenu;
  708.                 PROCEDURE TShadeMenu.Draw(area: Rect); OVERRIDE;
  709.                 FUNCTION TShadeMenu.FindItem(hitPt: Point): INTEGER; OVERRIDE;
  710.                 PROCEDURE TShadeMenu.Highlight(whichItem: INTEGER; turnItOn: BOOLEAN); OVERRIDE;
  711.  
  712.                 END;
  713.  
  714.     IMPLEMENTATION
  715.  
  716.         {$I UDrawShapes.inc1.p}
  717.  
  718. END.
  719.